package com.zky.system.controller;


import com.zky.system.domain.Dictionarydetail;
import com.zky.system.query.DictionarydetailQuery;
import com.zky.system.service.DictionarydetailService;
import com.zky.util.AjaxResult;
import com.zky.util.PageList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@ResponseBody
//@Controller
@RestController//相当于上面两个注解的整合
@RequestMapping("/dictionarydetail")
@Api(value = "部门接口类",description = "处理部门的crud操作")
public class DictionarydetailController {

    @Autowired
    private DictionarydetailService dictionarydetailService;

    /**
     *
     * 查询单个
     * @param id
     * @return
     */
    @ApiOperation(value = "查询单个")
    @GetMapping("/{id}")
    public Dictionarydetail findOne(@PathVariable("id")Long id){
        return dictionarydetailService.findOne(id);

    }

    /**
     * 查询所有
     * @return
     */
    @ApiOperation(value = "查询所有")
    @GetMapping()
    public List<Dictionarydetail> findAll(){
        return dictionarydetailService.findAll();
    }

    /**
     * 删除单个
     * @param id
     * @return
     */
    //http://localhost:8080/dictionarydetail/1
    @ApiOperation(value = "删除单个")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id")Long id){
        try {
            dictionarydetailService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }

    }

    /**
     * 批量删除
     * @param
     * @return
     */
    //http://localhost:8080/dictionarydetail/1
    @ApiOperation(value = "批量删除")
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        try {
            dictionarydetailService.patchDelete(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }

    }
    /**
     * 添加或者修改
     * @param dictionarydetail
     * @return
     */
    @ApiOperation(value = "添加或者修改")
    @PutMapping()
    public AjaxResult addOrUpdate(@RequestBody Dictionarydetail dictionarydetail){
        try {
            if(dictionarydetail.getId()==null){
                dictionarydetailService.add(dictionarydetail);
            }else{
                dictionarydetailService.update(dictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }

    }

    /**
     * 高级查询和分页
     * @param dictionarydetailQuery
     * @return
     */
    @ApiOperation(value = "高级查询和分页")
    @PostMapping("getType")
    public PageList<Dictionarydetail> findQuery(@RequestBody DictionarydetailQuery dictionarydetailQuery){
        return dictionarydetailService.pageQuery(dictionarydetailQuery);
    }


    /**
     *
     * 查询单个
     * @param id
     * @return
     */
    @ApiOperation(value = "查询单个")
    @GetMapping("getType/{id}")
    public List<Dictionarydetail> findType(@PathVariable("id")Long id){
        return dictionarydetailService.getType(id);

    }

}
